﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LiveCPEWinForm.Gestionnaire;
using LiveCPEWinForm.LiveCPEWS;

namespace LiveCPEWinForm.comp
{
    public partial class CsFriends : UserControl
    {
        private GestAPP lGestAPP;

        public CsFriends(GestAPP pGestAPP)
        {
            InitializeComponent();
            //gestionnaire d'application
            lGestAPP = pGestAPP;
            // Refresh
            lblStatus.Text = "You have " + Convert.ToString(lGestAPP.GestFriends.ListFriend.Count) + " friends !";
            InitFriend();
            InitNoFriend();
        }
        public void InitFriend()
        {
            // Gestion des amis
            int lTop = 190;
            foreach (UserWS usr in lGestAPP.GestFriends.ListFriend)
            {
                CsFriend cs = new CsFriend(usr);
                cs.Parent = this;
                // Augmentation de la hauteur
                this.Height += cs.Height + 20;
                cs.Left = 60;
                cs.Top = lTop;
                // Interespace
                lTop += cs.Height + 20;
                cs.Refresh();
            }
        }
        public void InitNoFriend()
        {
            // Suppression
            cbNoFriend.Items.Clear();
            // Ajout des non amis
            foreach (UserWS usr in lGestAPP.GestFriends.ListNoFriend)
            {
               if(usr.UserName != lGestAPP.UserName)
                   cbNoFriend.Items.Add(usr.UserName);
            }
        }

        private void btnPubli_Click(object sender, EventArgs e)
        {
            if (cbNoFriend.Text.Length > 0)
            {
                lblRquest.Text = lGestAPP.GestFriends.AddFriend(cbNoFriend.Text);
            }
        }

        private void CsFriends_Load(object sender, EventArgs e)
        {

        }
    }
}
